package com.xbongbong.pro.statistic.help.strategy.field.method;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.statistic.manager.feign.StatisticsWorkOrderV2FeignClient;
import com.xbongbong.pro.statistic.help.strategy.field.FieldAnalysisStrategy;
import com.xbongbong.pro.statistic.pojo.FieldAnalysisPojo;
import com.xbongbong.pro.statistic.pojo.dto.FieldAnalysisDTO;
import com.xbongbong.pro.statistic.pojo.vo.FieldAnalysisVO;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * @author 李翔
 * @date 2023/1/30
 * @description
 */
@Component
public class WorkOrderV2ProcessNodeFieldAnalysis implements FieldAnalysisStrategy {

    @Resource
    private StatisticsWorkOrderV2FeignClient statisticsWorkOrderV2FeignClient;

    @Override
    public Map<String, String> doAnalysisField(FieldAnalysisPojo fieldAnalysisPojo) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        FieldAnalysisDTO fieldAnalysisDTO = new FieldAnalysisDTO(fieldAnalysisPojo);
        BeanUtil.copyProperties(fieldAnalysisPojo, fieldAnalysisDTO);
        XbbResponse<FieldAnalysisVO> nodeNameMap = statisticsWorkOrderV2FeignClient.getNodeNameMap(fieldAnalysisDTO, lang);
        return nodeNameMap.getResult().getRes();
    }
}
